﻿/*
 * Returns the specified integer under the YYYYMMDD format as a date.
 */
create function [Int].[ToDate] ( @p_Integer int )
returns date as
begin

  if Len( @p_Integer ) = 8 and Int.TryParse( @p_Integer ) is not null
  begin
    return Date.FromParts( Substring( Cast( @p_Integer as varchar(8) ), 1, 4),
                           Substring( Cast( @p_Integer as varchar(8) ), 5, 2),
                           Substring( Cast( @p_Integer as varchar(8) ), 7, 2) );
  end
  
  return null;
  
end